<?php
namespace App\Domain\Examples;

use App\Model\Examples\ArticleList as ModelCURD;
use App\Model\Examples\ArticleType as TypeCURD;

class ArticleList {
    public function getArticleByTitle($name){
        $type=new TypeCURD();
        $model=new ModelCURD();
        $list=$type->getTypeIDByName($name);

        $students= json_decode($list, true);//得到的是 array
//        return $model->getArticleByTID($students[0]['id']);
        return $list.'0000'.count($students);
    }
    public function insert($newData) {
        //$newData['post_date'] = date('Y-m-d H:i:s', $_SERVER['REQUEST_TIME']);

        $model = new ModelCURD();
        return $model->insert($newData);
    }

    public function update($id, $newData) {
        $model = new ModelCURD();
        return $model->update($id, $newData);
    }

    public function get($id) {
        $model = new ModelCURD();
        return $model->get($id);
    }
    public function getDetailByTypeID($id){
        $model=new ModelCURD();
        return $model->getArticleByTID($id);
    }
    public function delete($id) {
        $model = new ModelCURD();
        return $model->delete($id);
    }
    public function getAllCitysByWord($word){
        $model = new ModelCURD();
        return $model->getAllCitysByWord($word);
    }
    public function getCitysByPingName($word){
        $model = new ModelCURD();
        return $model->getCitysByPingName($word);
    }
    public function getList( $page, $perpage) {
        $rs = array('items' => array(), 'total' => 0);

        $model = new ModelCURD();
        $items = $model->getListItems( $page, $perpage);
        $total = $model->getListTotal();

        $rs['items'] = $items;
        $rs['total'] = $total;

        return $rs;
    }
}
